package com.yunshang.shoppingmall.controller;

import com.yunshang.shoppingmall.common.MessageConstants;
import com.yunshang.shoppingmall.common.Response;
import com.yunshang.shoppingmall.entity.Area;
import com.yunshang.shoppingmall.service.AreaService;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.swing.*;
import java.util.List;

@Controller
public class AreaController {
    @Autowired
    AreaService areaService;
    //跳转城市页面
    @RequestMapping("/getAreaList")
    public String getAreaList(Model map){
        List<Area> areaList =areaService.selectListAll();
        map.addAttribute("areaList",areaList);
        return "area/areaList";
    }

    //获取地址信息
    @ResponseBody
    @RequestMapping("/getArea")
    public Response getArea(String parentId,String level){
        System.out.println(parentId+"=="+level);
        List<Area> areaList=areaService.selectArea(Integer.parseInt(parentId),Integer.valueOf(level));
        return new Response(MessageConstants.MSG_SUCCESS,areaList,"");
    }


}
